﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PhaseUatt3
{
    public partial class Form1 : Form
    {
        public int serNumb = 0; 

        public Form1()
        {
            InitializeComponent();

            //начальные условия
            textBox1.Text = "3";
            textBox2.Text = "0,5";
            textBox3.Text = "0";

            textBox4.Text = "0,01"; //шаг по времени

            //параметры системы
            textBox5.Text = "3";
            textBox6.Text = "2";
            textBox7.Text = "1";

            textBox8.Text = "3";
            textBox9.Text = "10";
            textBox10.Text = "0,1";
            textBox11.Text = "1";

            //параметры метода 
            textBox12.Text = "100";
            textBox13.Text = "1e-6";

            chart1.Series.Clear();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            chart1.Series.Clear();
            dataGridView1.Rows.Clear();
            serNumb = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double w0;
            double f0;
            double df0;
            double h0;
            double k;
            double F;
            double J;
            double n;
            double g;
            double b;
            double m;

            double.TryParse(textBox1.Text, out w0);
            double.TryParse(textBox2.Text, out f0);
            double.TryParse(textBox3.Text, out df0);
            double.TryParse(textBox4.Text, out h0);
            double.TryParse(textBox5.Text, out k);
            double.TryParse(textBox6.Text, out F);
            double.TryParse(textBox7.Text, out J);
            double.TryParse(textBox8.Text, out n);
            double.TryParse(textBox9.Text, out g);
            double.TryParse(textBox10.Text, out b);
            double.TryParse(textBox11.Text, out m);

            double eps;
            double.TryParse(textBox13.Text, out eps);
            int maxStep;
            int.TryParse(textBox12.Text, out maxStep);



            regulatorConditions solv = new regulatorConditions(m, F, g, J, n, b, k, w0, f0, df0, h0, maxStep);
            solv.Task(eps);
            double t = 0;

            chart1.Series.Add("f, w " +serNumb.ToString());
            chart1.Series[serNumb].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            for (int i = 1; i <= maxStep; i++)
            {
                t = t + solv.h[i-1];
                chart1.Series[serNumb].Points.AddXY(solv.f[i], solv.w[i]);
                dataGridView1.Rows.Add(t, solv.w[i], solv.f[i], solv.df[i], solv.s[i-1], solv.h[i]);

            }
            serNumb++;

        }
    }
}
